package com.hx.localmiaosha.dao;

import com.hx.common.domain.MiaoshaGoods;
import com.hx.common.vo.GoodsVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface LocalGoodsDao {
	
	@Select("select g.*,mg.stock_count, mg.start_date, mg.end_date,mg.miaosha_price from miaosha_goods mg left join goods g on mg.goods_id = g.id")
	public List<GoodsVo> listGoodsVo();

	@Select("select g.*,mg.stock_count, mg.start_date, mg.end_date,mg.miaosha_price from miaosha_goods mg left join goods g on mg.goods_id = g.id where g.id = #{goodsId}")
	public GoodsVo getGoodsVoByGoodsId(@Param("goodsId") long goodsId);

	@Select("select * from miaosha_goods where goods_id = #{goodsId}")
	public MiaoshaGoods getMiaoshaGoodsVoByGoodsId(@Param("goodsId") long goodsId);

	@Update("update miaosha_goods set stock_count = stock_count - 1,version = version+1 where goods_id = #{goodsId} and version = #{version}")
	public int reduceStock(MiaoshaGoods miaoshaGoods);

	@Update("update miaosha_goods set stock_count = stock_count + #{count} where goods_id = #{goodsId}")
	public int releaseStock(@Param("goodsId") long goodsId,@Param("count") int count);
}
